package io.renren.wechat.service.impl;

import com.alibaba.druid.support.spring.stat.SpringStatUtils;
import com.alibaba.druid.util.StringUtils;
import io.renren.wechat.vo.FriendVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.wechat.dao.UsersDao;
import io.renren.wechat.entity.UsersEntity;
import io.renren.wechat.service.UsersService;


@Service("usersService")
public class UsersServiceImpl extends ServiceImpl<UsersDao, UsersEntity> implements UsersService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<UsersEntity> page = this.page(
//                new Query<UsersEntity>().getPage(params),
//                new QueryWrapper<UsersEntity>()
//        );
//
//        return new PageUtils(page);

        QueryWrapper<UsersEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.eq("id",key)
                    .or().eq("username",key)
                    .or().like("nickname",key)
            ;
        }
        IPage<UsersEntity> page = this.page(
                new Query<UsersEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }



}